package com.cmcc.pcap.packet.udp.pfcp;

/*
 * @author        : Wang
 * @data          : 2023/5/1016:16
 * @description   : some description
 */

import com.cmcc.packet.entity.PfcpEntity;
import com.cmcc.pcap.packet.udp.UdpConnection;
import com.cmcc.pcap.packet.udp.UdpProtocolHandler;
import com.cmcc.pcap.packet.udp.pfcp.xdr.PfcpXdrGenerate;
import com.cmcc.pcap.packet.udp.quic.QuicHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.List;

public class PfcpHandler extends UdpProtocolHandler<PfcpEntity> {
    private static Logger logger = LogManager.getLogger(QuicHandler.class);
    private PfcpXdrGenerate pxg;

    public PfcpHandler() {
        pxg = new PfcpXdrGenerate();
    }

    @Override
    public List<PfcpEntity> handle(UdpConnection udpConnection, String taskId) {
        logger.debug("start execute quic packet handler");

        logger.debug(new Date(udpConnection.lastPacketTime));//最后一个packet的处理时间(注:非抓包时间)
        long pcapTimestamp  = udpConnection.lastPacketTime;//pcap的timestamp的单位是秒，这里需要转成毫秒
        logger.debug(new Date(pcapTimestamp));//最后一个packet的抓包时间


        List<PfcpEntity> xdrquicEntityList = pxg.generate(udpConnection,taskId);
        logger.debug("this connection <"+udpConnection.connectionKey+"> save into quic packet entity !");

        return xdrquicEntityList;
    }
}
